<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>滨海基金 -角色管理</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<!-- Data Tables -->
<link href="css/plugins/dataTables/dataTables.bootstrap.css"
	rel="stylesheet">

<link href="css/animate.min.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
<link href="css/jquery-confirm.css" rel="stylesheet">
<link href="css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<script src="js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/plugins/jeditable/jquery.jeditable.js"></script>
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script type="text/javascript"
	src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script src="js/plugins/modal/bootstrap-modal.js"></script>
<script src="js/jquery-confirm.js"></script>
<script src="js/common.js"></script>
<style type="text/css">
* {
	margin: 0px;
}

.modal-body {
	max-height: 400px;
	overflow-y: auto;
}

#myModalLabel {
	text-align: center;
}

.childspan {
	font-size: 14px;
	margin: 0px 7px;
}

.parentspan {
	font-size: 20px;
	margin-left: 10px;
}

#authorityUL li {
	margin-top: -20px;
}

span[class*="parentspan"], span[class*="childspan"] {
	cursor: pointer;
}

#add {
	cursor: pointer;
}
/* dataTables列内容居中 */
.table>tbody>tr>td {
	text-align: center;
}

/* dataTables表头居中 */
.table>thead:first-child>tr:first-child>th {
	text-align: center;
}
</style>

<script type="text/javascript">
	var table;
	var darw = 0;
	$(function() {

		//提示信息
		var lang = {
			"sProcessing" : "<div style=\"float:right;width:50%\" >处理中...</div>",
			"sLengthMenu" : "每页 _MENU_ 项",
			"sZeroRecords" : "没有匹配结果",
			"sInfo" : "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
			"sInfoEmpty" : "当前显示第 0 至 0 项，共 0 项",
			"sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix" : "",
			"sSearch" : "搜索:",
			"sUrl" : "",
			"sEmptyTable" : "表中数据为空",
			"sLoadingRecords" : "载入中...",
			"sInfoThousands" : ",",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上页",
				"sNext" : "下页",
				"sLast" : "末页",
				"sJump" : "跳转"
			},
			"oAria" : {
				"sSortAscending" : ": 以升序排列此列",
				"sSortDescending" : ": 以降序排列此列"
			}
		};

		//初始化表格
		table = $("#roleDatatabel")
				.dataTable(
						{

							"fnDrawCallback" : function() {
								var api = this.api();
								var startIndex = api.context[0]._iDisplayStart;//获取到本页开始的条数
								api.column(0).nodes().each(function(cell, i) {
									cell.innerHTML = startIndex + i + 1;
								});

							},
							language : lang, //提示信息
							autoWidth : false, //禁用自动调整列宽
							stripeClasses : [ "odd", "even" ], //为奇偶行加上样式，兼容不支持CSS伪类的场合
							processing : true, //隐藏加载提示,自行处理
							serverSide : true, //启用服务器端分页
							searching : false, //禁用原生搜索
							orderMulti : false, //启用多列排序
							order : [], //取消默认排序查询,否则复选框一列会出现小箭头
							renderer : "bootstrap", //渲染样式：Bootstrap和jquery-ui
							pagingType : "simple_numbers", //分页样式：simple,simple_numbers,full,full_numbers
							"aLengthMenu" : [ 10 ],
							"bLengthChange" : false,
							ordering : false, //关闭排序图标
							bStateSave : true, //刷新 停留在当前页
							ajax : function(data, callback, settings) {
								//封装请求参数
								var param = {};
								param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
								param.start = data.start;//开始的记录序号
								param.page = (data.start / data.length) + 1;//当前页码
								param.darw = darw; //计数器

								var rName = $("#rName").val().trim();
								if (rName != null && rName != "") {
									param.rName = rName;
								}

								//console.log(param);
								//ajax请求数据
								$
										.ajax({
											type : "POST",
											url : "queryRole.do",
											cache : false, //禁用缓存
											data : param, //传入组装的参数
											dataType : "json",
											success : function(result) {

												//console.log(result);
												//setTimeout仅为测试延迟效果
												//封装返回数据
												var returnData = {};
												draw = result.draw;//后台返回的计数器
												returnData.draw = result.draw;//这里直接自行返回了draw计数器,应该由后台返回
												returnData.recordsTotal = result.total;//返回数据全部记录
												returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
												returnData.data = result.data;//返回的数据列表

												//console.log(returnData);
												//调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
												//此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
												callback(returnData);
											},
											error : function() {
												sweetAlert("异常", "网络出现异常!",
														"error");
											}
										});
							},
							//列表表头字段
							columns : [ {
								"data" : null
							}, {
								"data" : "id",
								"visible" : false
							}, {
								"data" : "rname"
							}, {
								"data" : "state"
							}

							],
							columnDefs : [
									{
										"targets" : [ 4 ], //第五列加一条 自定义列
										"data" : "id", //数据列名
										"render" : function(data, type, full) { //返回自定义的内容

											return "<a class=\"btn btn-info btn-xs\" data-toggle=\"modal\"  onclick=\"roleModal("
													+ data
													+ ")\"   href=\"\">"
													+ "授权<\a>&nbsp;<a class=\"btn btn-primary  btn-xs\"   href=\"javascript:void(0);\" onclick=\"toEdit("
													+ data
													+ ")\">编辑<\a>&nbsp;"
													+ "<a class=\"btn btn-danger  btn-xs\" href=\"javascript:void(0);\" onclick=\"delRole("
													+ data + ")\">删除<\a>";

										}

									}, {

										"targets" : [ 3 ],
										"render" : function(data, type, full) {
											var status = "";
											if (data == 0) {
												status = "启用";
											} else if (data == 2) {
												status = "禁用";
											}
											return status;
										}

									}

							]
						})//.api();
		//此处需调用api()方法,否则返回的是JQuery对象而不是DataTables的API对象

	});
</script>

<style type="text/css">
#gaga {
	position: absolute;
	z-index: 9999;
	display: none;
}
</style>
<script type="text/javascript">
	window.onload = function() {
		var div = document.getElementById("gaga");
		div.style.position = "absolute";
		div.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight - div.offsetHeight) / 2)
				+ "px";
		div.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - div.offsetWidth) / 2)
				+ "px";
	};
</script>
</head>
<body class="gray-bg">
	<div class="row">
		<div id="gaga">
			<img alt="" src="img\role-ajax-loader.gif">

		</div>
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-title">
					<h5>角色权限更改</h5>
					<div class="ibox-content">
						<div class="input-group col-md-3"
							style="margin-top: 0px; positon: relative; float: left; bottom: -5px;">
							<input id="rName" type="text" class="form-control "
								placeholder="请输入关键字（角色名称）"/ > <span
								class="input-group-btn">
								<button onclick="search()" class="btn btn-info btn-search">查询</button>
								<button class="btn btn-info btn-search" id="add"
									class="fa fa-plus" style="margin-left: 5px">添加</button>
							</span>
						</div>
						<table id="roleDatatabel"
							class="table table-striped table-bordered table-hover dataTables-example dataTable">
							<thead>
								<tr style="height: 30px">
									<th style="width: 10px" align="center">序号</th>
									<th style="width: 50px" align="center">id</th>
									<th style="width: 100px" align="center">角色名称</th>
									<th style="width: 100px" align="center">状态</th>
									<th style="width: 50px" align="center">操作</th>
								</tr>
							</thead>
							<%-- 	<c:forEach items="${requestScope.roleList }" var="role"  varStatus="statu">
									<tr class="gradeA" style="height: 30px" >
										<td align="center" >${statu.index+1 }</td>
										<td align="center" >${role.rname }</td>
										
										<td class="center" style="padding: 0px" align="center" >
											<a class="btn btn-info btn-xs" data-toggle="modal" id="roleModal${statu.index+1 }" onclick="roleModal(${role.id})"   href="javascript:void(0);">授权</a>
											<a class="btn btn-primary  btn-xs"   href="javascript:void(0);" onclick="toEdit(${role.id})">编辑</a>
											<a class="btn btn-danger  btn-xs" href="javascript:void(0);" onclick="delRole(${role.id})">删除</a>
										</td>
									</tr>
							
							</c:forEach> --%>
						</table>
					</div>
				</div>
			</div>
		</div>


		<div class="modal fade  " id='show'>
			<div class="modal-dialog">
				<div class="modal-content">

					<div class="modal-header">
						<button class="close" data-dismiss='modal'>×</button>
						<h2 class="modal-title" id="myModalLabel">角色权限管理</h2>
					</div>
					<div class="modal-body">
						<!--  <div id="gaga1">
                     	 <img alt="" src="img\role-ajax-loader.gif"> 
                     </div>  -->
						<form action="" id="relationForm">
							<ul id="authorityUL" unselectable="on"
								onselectstart="return false;" style="-moz-user-select: none;">


							</ul>

						</form>

					</div>

					<div class="modal-footer">
						<div align="center">

							<button class="btn btn-primary" data-toggle='modal'
								id="modifyRelationSave">保存</button>
							<!-- <button class="btn btn-default" data-toggle='modal' id="btnClose">关闭</button> -->
						</div>
					</div>
				</div>
			</div>
		</div>

		<!--添加角色窗口 -->
		<div class="modal fade  " id='addRoleModal'>
			<div class="modal-dialog" style="width: 400px; height: 500px;">
				<div class="modal-content">
					<div class="modal-header">
						<button class="close" data-dismiss='modal'>×</button>

						<h2 class="modal-title" align="center">添加角色信息</h2>
					</div>

					<div class="modal-body" align="center">

						<form id="addRoleInfoForm">
							<table align="center">
								<tr>
									<td>角色名称<span style="color: red;">*</span>：
									</td>
									<td><input type="text" class="form-control" id="rname"
										name="rname"></td>
								</tr>
							</table>
						</form>

					</div>
					<div class="modal-footer" align="center">
						<div align="center">

							<button class="btn btn-primary" id="btnRoleAdd">确认</button>
							<!-- <button class="btn btn-default" data-toggle='modal'
								id="btnAddClose">关闭</button> -->
						</div>
					</div>
				</div>
			</div>
		</div>


		<div class="modal fade  " id='editRoleModal'>
			<div class="modal-dialog" style="width: 400px; height: 500px;">
				<div class="modal-content">
					<div class="modal-header">
						<button class="close" data-dismiss='modal'>×</button>
						<h2 class="modal-title" align="center">修改角色信息</h2>
					</div>

					<div class="modal-body" align="center">

						<form id="editRoleInfoForm"></form>

					</div>
					<div class="modal-footer" align="center">
						<div align="center">
							<button class="btn btn-primary" id="btnRoleEdit">确认</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script>
		$(document).ready(function() {

			$("[data-toggle='popover']").popover();

			//关闭具体权限列表
			$("#btnClose").click(function() {
				$("#show").modal("hide");
			});

			//关闭添加窗口
			$("#btnAddClose").click(function() {
				$("#addRoleModal").modal("hide");
			});

			//显示添加窗口
			$("#add").click(function() {
				$("#rname").val("");
				$("#addRoleModal").modal("show");
			});

			//添加角色操作
			$("#btnRoleAdd").click(function() {
				var rname = $("#rname").val();

				if (rname.trim() == "") {
					sweetAlert("温馨提示", "请输入角色名称!", "warning");
					return;
				}

				//请求Rolecontroller后台

				$.ajax({
					url : "addRole.do",
					data : $("#addRoleInfoForm").serializeArray(),
					type : "post",
					dataType : "json",
					success : function(result) {
						if (result.data == 1) {
							swal({
								title : "提示",
								text : "添加成功！",
								type : "success",
								confirmButtonColor : "#DD6B55",
								confirmButtonText : "确定",
								closeOnConfirm : true
							}, function() {
								$("#addRoleModal").modal("hide");
								search();
							});

						} else if (result.data == 0) {
							sweetAlert("异常", "暂无数据!", "error");
						} else {
							sweetAlert("异常", "出现未知错误!", "error");
						}

					},
					error : function() {
						sweetAlert("异常", "网络出现异常!", "error");
					}

				});// ajax end;
			});

			//执行修改 保存
			$("#btnRoleEdit").click(function() {
				$.ajax({
					url : "editRole.do",
					data : $("#editRoleInfoForm").serializeArray(),
					dataType : "json",
					type : "post",
					success : function(result) {
						if (result.data == 1) {
							swal({
								title : "提示",
								text : "修改成功！",
								type : "success",
								confirmButtonColor : "#DD6B55",
								confirmButtonText : "确定",
								closeOnConfirm : true
							}, function() {
								$("#editRoleModal").modal("hide");
								search();
							});
						} else if (result.data == -1) {

							sweetAlert("异常", "出现未知错误!", "error");
						} else {

							sweetAlert("异常", "暂无数据!", "error");
						}
					},
					error : function() {

						sweetAlert("异常", "网络出现异常!", "error");
					}

				})

			})

		});

		//显示具体权限列表
		function roleModal(rid) {
			$("#gaga").css("display", "block");

			$
					.ajax({
						url : "toAuthority.do",
						data : {
							roleId : rid
						},
						type : "post",
						dataType : "json",
						success : function(result) {
							$("#gaga").css("display", "none");
							if (result.data == 1) {//success
								//alert(result.content);
								//$("#authorityUL").html(result.content);

								var parentList = result.menuList;
								var childrenList = result.relationList;
								var html = "";
								for (var i = 0; i < parentList.length; i++) {
									html += "<li class='parentli"+i+"' style='list-style-type: none;'>  ";
									html += " <input class='parentlicb"
											+ i
											+ "' name='parentMenuId' onclick='choose(this)' type='checkbox' value='"
											+ parentList[i].id + "'>";
									html += "<span onclick=choose(this,'span') class='parentspan"
											+ i
											+ "'>"
											+ parentList[i].name
											+ "</span>";
									var html_c = "<ul>";
									var childMenus = parentList[i].childMenus;//子级菜单
									for (var j = 0; j < childMenus.length; j++) {
										html_c += "<input type='hidden' name='parentMenuId' class='parentMenuId"+i+"'>";
										html_c += "<li class='childli"+i+"' style='list-style-type: none;display: inline;'>";
										var checkbox = " <input name='menuId' class='childlicb"
												+ i
												+ "' type='checkbox'  onclick='chooseChild(this)' value='"
												+ childMenus[j].id + "'>";
										checkbox += "<span onclick=chooseChild(this,'span') class='childspan"
												+ i
												+ "'>"
												+ childMenus[j].name
												+ "</span></li>";
										for ( var k in childrenList) {
											if (childrenList[k].oaMenu.id == childMenus[j].id) {
												checkbox = " <input name='menuId' class='childlicb"
														+ i
														+ "' type='checkbox' checked='true' onclick='chooseChild(this)' value='"
														+ childMenus[j].id
														+ "'>";
												checkbox += "<span onclick=chooseChild(this,'span') class='childspan"
														+ i
														+ "'>"
														+ childMenus[j].name
														+ "</span></li>";
											}
										}
										html_c += checkbox;
										if ((j + 1) % 4 == 0) {
											html_c += "</br>";
										}

									}
									html_c += "</ul> ";
									html += html_c;
									html += "</li>";
									html += "<hr style='height:1px; width:450px; border:none; border-top:1px #000 dashed ;'>";
								}
								html += "<input type='hidden' name='roleId' value='"+result.roleId +"'>";
								$("#authorityUL").html(html);
								//刷新父checkbox状态
								refreshCheckboxState($("input[type='checkbox'][class*='childlicb'][checked='true']"));

								$("#show").modal("show");
							} else if (result.data == -1) {//exception
								sweetAlert("错误", "出现未知错误!", "error");
							} else {
								sweetAlert("错误", "暂无数据!", "error");
							}

						},
						error : function() {
							sweetAlert("异常", "网络出现异常!", "error");
						}
					});
		}

		//设置权限
		$("#modifyRelationSave").click(function() {
			$("#gaga").css({
				"display" : "block"
			});
			$.ajax({
				url : "modifyAuthority.do",
				type : "post",
				dataType : "json",
				data : $("#relationForm").serializeArray()
				/* roleId:$("[name='roleId']").val(),
				parentMenuId:$("[name='parentMenuId']").val(),
				menuId:$("[name='menuId']").val() */
				,
				success : function(result) {
					$("#gaga").css({
						"display" : "none"
					});
					if (result.data == 1) {
						swal({
							title : "提示",
							text : "设置成功！",
							type : "success",
							confirmButtonColor : "#DD6B55",
							confirmButtonText : "确定",
							closeOnConfirm : true
						}, function() {
							$("#show").modal("hide");
							search();
						});
					} else if (result.data == 0) { //没查到数据

						sweetAlert("错误", "暂无数据!", "error");
					} else { //500

						sweetAlert("错误", "出现未知错误!", "error");
					}

				},
				error : function() {
					sweetAlert("异常", "网络出现异常!", "error");

				}
			})

		})

		//编辑前展示角色信息
		function toEdit(id) {
			$
					.ajax({
						url : "toEditRole.do",
						data : {
							id : id
						},
						type : "post",
						dataType : "json",
						success : function(result) {
							//editRoleTable= 展示 编辑前角色信息
							var editRoleTable = "<table  style='border-collapse:separate; border-spacing:10px;'>";
							editRoleTable += "<tr><td>角色名称<span style=\"color: red;\">*</span>：</td>";
							editRoleTable += "<td><input type=\"text\"  class=\"form-control\"  id=\"rname\" name=\"rname\" value=\"role.rname\"></td></tr>";
							editRoleTable += "<tr><td>是否启用<span style=\"color: red;\">*</span>：</td>";
							editRoleTable += "<td><select  class=\"form-control \"  id=\"state\" name=\"state\">";
							editRoleTable += "if0";
							editRoleTable += "if1";
							editRoleTable += "</select ></td></tr>";
							editRoleTable += "<input type=\"hidden\"  id=\"id\" name=\"id\" value=\"role.id\"></table>";

							if (result.data == 1) { //成功
								editRoleTable = editRoleTable.replace(
										"role.rname", result.role.rname);
								editRoleTable = editRoleTable.replace(
										"role.id", result.role.id);

								if (result.role.state == 0) {
									editRoleTable = editRoleTable
											.replace("if0",
													"<option value=\"0\" selected >启用</option>");
									editRoleTable = editRoleTable
											.replace("if1",
													"<option value=\"2\"  >禁用</option>");

								} else if (result.role.state == 1) {
									editRoleTable = editRoleTable
											.replace("if0",
													"<option value=\"0\"  >启用</option>");
									editRoleTable = editRoleTable
											.replace("if1",
													"<option value=\"2\" selected >禁用</option>");
								} else {
									editRoleTable = editRoleTable
											.replace("if0",
													"<option value=\"0\"  >启用</option>");
									editRoleTable = editRoleTable.replace(
											"if1",
											"<option value=\"2\" >禁用</option>");
								}

								$("#editRoleInfoForm").html(editRoleTable);
								$("#editRoleModal").modal("show"); //显示编辑窗口
							} else if (result.data == 0) { //没查到数据

								sweetAlert("异常", "暂无数据!", "error");
							} else { //500

								sweetAlert("错误", "出现未知错误!", "error");
							}

						},
						error : function() {
							sweetAlert("错误", "网络出现异常!", "error");
						}
					});
		}

		//删除角色
		function delRole(id) {
			swal({
				title : "提示",
				text : "确认删除该角色？",
				type : "warning",
				showCancelButton : true,
				confirmButtonColor : "#DD6B55",
				confirmButtonText : "确定",
				cancelButtonText : "取消",
				closeOnConfirm : false,
			}, function() {

				$.ajax({
					url : "delRole.do",
					data : {
						id : id
					},
					type : "post",
					dataType : "json",
					success : function(result) {
						if (result.data == 1) {

							swal({
								title : "提示",
								text : "删除成功！",
								type : "success",
								confirmButtonColor : "#DD6B55",
								confirmButtonText : "确定",
								closeOnConfirm : true
							}, function() {
								search();
							});

						} else if (result.data == -1) {

							sweetAlert("错误", "出现未知错误!", "error");
						} else {

							sweetAlert("错误", "暂无数据!", "error");
						}
					},
					error : function() {
						sweetAlert("异常", "网络出现异常!", "error");
					}

				})
			});
		}

		//处理选中还是全选
		function choose(v, isspan) {

			if (isspan == "span") {
				//obj就是等于 span  所以 得 span .prev（）一下获取到 checkbox
				v = $(v).prev();

				if (v.prop("checked")) {
					v.prop("checked", false);
				} else {
					v.prop("checked", true);
				}
			}

			var parentCB = "." + $(v).prop("class");
			var childli = $(parentCB).next().next("ul").children("li");
			/*  if(indeterminateFlag==1){  //如果是模糊状态点击
				 $(v).prop("checked",false);			
				 $(v).prop("indeterminate",false);
				 indeterminateFlag=0;
			 } */
			// alert("parentCB="+parentCB)
			if (indetMap.get(parentCB) == 1) { //如果是模糊状态点击
				$(v).prop("checked", false);
				$(v).prop("indeterminate", false);
				indetMap.set(parentCB, 0);
			}

			if ($(parentCB).prop("checked")) {
				//处理子级别 checkbox 全选

				childli.each(function() {
					$(this).children("input").prop("checked", true);
				})

			} else {
				//处理子级别 checkbox 全不选
				childli.each(function() {
					$(this).children("input").prop("checked", false);
				})

			}
		}

		//子级别 单选框调用的方法
		function chooseChild(obj, isspan) {
			var flag = 0;

			if (isspan == "span") {
				//obj就是等于 span  所以 得 span .prev（）一下获取到 checkbox
				obj = $(obj).prev();

				if (obj.prop("checked")) {
					obj.prop("checked", false);
				} else {
					obj.prop("checked", true);
				}

			}
			// obj=obj.get(0);
			//alert(obj);

			var childli = "." + $(obj).parent().prop("class");
			var childcb = $(childli).children("input");
			childcb.each(function() {
				if ($(this).prop("checked")) {
					flag += 1; //选中一个+1
				}

			})
			//循环完如果选中数量 满了就勾起父checkbox
			var parentCheckBox = $(childli).parent().siblings("input"); //父checkbox对象
			var parentClass = "." + parentCheckBox.prop("class");
			//alert("parentClass="+parentClass);
			if (flag == childcb.size()) {
				parentCheckBox.prop("indeterminate", false);
				parentCheckBox.prop("checked", true);

			} else if (flag > 0) {
				// indeterminateFlag=1;
				indetMap.set(parentClass, 1); //类作为 key value为状态
				parentCheckBox.next().next().children("input").val(
						parentCheckBox.val());
				parentCheckBox.prop("indeterminate", true);

				parentCheckBox.prop("checked", false);
			} else {
				// indeterminateFlag=0;
				indetMap.set(parentClass, 0); //类作为 key value为状态
				parentCheckBox.prop("checked", false);
				parentCheckBox.prop("indeterminate", false);
				parentCheckBox.next().next().children("input").val("");
			}

		}

		//刷新 checkbox父选项状态
		function refreshCheckboxState(checkboxList) {
			if (checkboxList != null && checkboxList.size() > 0) {
				for (var i = 0; i < checkboxList.size(); i++) {

					var flag = 0;
					var childli = "."
							+ $(checkboxList[i]).parent().prop("class");
					var childcb = $(childli).children("input");
					childcb.each(function() {
						if ($(this).prop("checked")) {
							flag += 1; //选中一个+1
						}

					})
					//循环完如果选中数量 满了就勾起父checkbox
					var parentCheckBox = $(childli).parent().siblings("input");
					var parentcb = "." + parentCheckBox.prop("class"); //类名
					if (flag == childcb.size()) {
						parentCheckBox.prop("checked", true);
						parentCheckBox.prop("indeterminate", false);
					} else if (flag > 0) {
						//indeterminateFlag=1;
						indetMap.set(parentcb, 1);
						parentCheckBox.prop("indeterminate", true);
						parentCheckBox.prop("checked", false);
						parentCheckBox.next().next().children("input").val(
								parentCheckBox.val());
					} else {

						// indeterminateFlag=0;
						indetMap.set(parentcb, 0);
						parentCheckBox.prop("checked", false);
						parentCheckBox.prop("indeterminate", false);
						parentCheckBox.next().next().children("input").val("");
					}

				}

			}

		}

		//查询
		function search() {
			/* var oSettings = table.fnSettings();  
			oSettings._iDisplayStart = 0;  
			table.fnDraw(oSettings);   */
			table.fnDraw();
		}
	</script>


	<script type="text/javascript">
		var cbflag = 1; //标识checkbox  状态 1为  没选  2为 选中
		var indeterminateFlag = 0; //是否模糊状态 0 不是 1 是 
		var indetMap = new Map(); //父选款 类名作为key+状态判断 作为准确性
	</script>
</body>

</html>